package com.open.party.cloud.view.task.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.open.party.cloud.R;
import com.open.party.cloud.model.task.TaskRateEntity;
import com.sinothk.android.utils.inters.OnSuperListener;

import org.jetbrains.annotations.NotNull;

/**
 * 任务进度适配器
 */
public class TaskRateAdapter extends SimpleBaseAdapter<TaskRateEntity, TaskRateAdapter.ViewHolder> {

//    String fromWhere = "";
    String statusCode = "";
    private OnSuperListener<TaskRateEntity> onSuperListener;

//    public void setFromWhere(String fromWhere, String statusCode) {
////        this.fromWhere = fromWhere;
//        this.statusCode = statusCode;
//    }

//    public void setOnSuperListener(OnSuperListener<TaskRateEntity> onSuperListener) {
//        this.onSuperListener = onSuperListener;
//    }

    public TaskRateAdapter(Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.rate_desc_item_view;
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void bindView(ViewHolder viewHolder, TaskRateEntity taskRateEntity, int position) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            viewHolder.rateDescTv.setText(Html.fromHtml(taskRateEntity.getDescription(), Html.FROM_HTML_MODE_LEGACY));
        } else {
            viewHolder.rateDescTv.setText(Html.fromHtml(taskRateEntity.getDescription()));
        }
        viewHolder.dateTv.setText("完成时间：" + taskRateEntity.getEndTime());
//        viewHolder.rateTv.setText("完成度：" + taskRateEntity.getRate() + "%");

//        if ("receive".equals(fromWhere) && "SHZ".equals(statusCode)) {
//            viewHolder.bottomView.setVisibility(View.VISIBLE);
//            if (onSuperListener != null) {
//
//                viewHolder.bottomView.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        onSuperListener.onClick(position, taskRateEntity, "bottomView");
//                    }
//                });
//            }
//        } else {
//            viewHolder.bottomView.setVisibility(View.GONE);
//        }
    }

    @NonNull
    @Override
    protected ViewHolder onNewViewHolder(View view) {
        return new ViewHolder(view);
    }

    static class ViewHolder {

        TextView rateDescTv, dateTv, rateTv;//, bottomView

        ViewHolder(View view) {
            rateDescTv = view.findViewById(R.id.rateDescTv);
            dateTv = view.findViewById(R.id.dateTv);
//            rateTv = view.findViewById(R.id.rateTv);
//            bottomView = view.findViewById(R.id.bottomView);
        }
    }
}
